﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AntiObesity.Base;
using AntiObesity.Base.Managers;

namespace AntiObesity.Services
{
    [WebService(Namespace = "http://antiobesity-project.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class IntakeServices : System.Web.Services.WebService
    {
        [WebMethod]
        public void PersistIntakes(List<Intake> intakes)
        {
            foreach (var intake in intakes)
                IntakeManager.Persist(intake);
        }

        [WebMethod]
        public List<Intake> GetIntakes(DateTime day, Guid userID)
        {
            return IntakeManager.GetAll(
                new DateTime(day.Year, day.Month, day.Day),
                new DateTime(day.Year, day.Month, day.Day + 1),
                userID);
        }

        [WebMethod]
        public float GetTotalCalories(DateTime from, DateTime to, Guid userID)
        {
            return IntakeManager.GetTotalCalories(from, to, userID);
        }

        [WebMethod]
        public DateTime GetLastIntakeDate(Guid userID)
        {
            return IntakeManager.FindLastIntakeDate(userID);
        }
    }
}
